'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-03-22 13:49:12
'''
class Solution:
    def sumFourDivisors(self, nums: List[int]) -> int:
        tmp_max = max(nums)
        prime = [True for _ in range(tmp_max)]
        import math
        for i in range(2, int(math.sqrt(tmp_max))):
            if prime[i]:
                j = i*i
                while j<tmp_max:
                    prime[j] = False
                    j += i
        prime = [i for i in range(2, tmp_max) if prime[i]]
        def get_factor(num, prime):
            # print(prime)
            for i in prime:
                if i*i > num:
                    break
                if num%i == 0 and i*i != num and num//i in prime:
                    # print(num, i)
                    return True, 1+num+i+num//i
                if i**3 == num:
                    return True, 1+num+i+num//i
                
            return False, 0

        re = 0
        for num in nums:
            tel, count = get_factor(num, prime)
            # print(num, tel, count)
            if tel:
                re += count
        return re
                